//
//  userInformationViewController.m
//  SoundPill
//
//  Created by 宋旭东 on 15/6/23.
//  Copyright (c) 2015年 宋旭东. All rights reserved.
//

#import "userInformationViewController.h"
#import "MJRefresh.h"
#import "Follow_ViewController.h"
#import "Fans_ViewController.h"
#import "chatViewController.h"
#import "UIViewController+MMDrawerController.h"
#import "MobClick.h"
#import "JCAlertView.h"
#import "AppDelegate.h"
@interface userInformationViewController ()<UITableViewDelegate,UITableViewDataSource,UIScrollViewDelegate,MJRefreshBaseViewDelegate>
{
    int page;
    int pages;
    MJRefreshSystemHeaderView *refreshHeader;
    MJRefreshFooterView *refreshFooter;
    UIImageView *_timeLine;
    NSString *playingAudioId;
}

@property (strong, nonatomic) UIScrollView *ownScrollView;
@property (strong, nonatomic) ownInforView *HeaderInfor;
@property (strong, nonatomic) UITableView *worksTableView;
@property (strong, nonatomic) UIImageView *NoworksView;
@property (strong, nonatomic) NSMutableArray *worksArray;
@property (strong, nonatomic) playerTableViewController *player;

@end

@implementation userInformationViewController
-(instancetype)initWithSelfUid:(NSString *)uid
{
    self = [super init];
    if (self) {
        self.hidesBottomBarWhenPushed = YES;
        self.selfUid = uid;
        self.isNeedPush = YES;
        self.worksArray = [[NSMutableArray alloc] init];
        [self AFNetworking:1 uid:uid refreshing:nil];
        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 30)];
        _titleLabel.textColor = [UIColor blackColor];
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        _titleLabel.font = [UIFont boldSystemFontOfSize:17];
        self.navigationItem.titleView = _titleLabel;
//        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTitle:) name:@"changeTitle" object:nil];
        
    }
    return self;
}
- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];
    [MobClick beginLogPageView:@"其他用户"];
}
- (void)viewDidDisappear:(BOOL)animated
{
    [super viewDidDisappear:YES];
    [MobClick endLogPageView:@"其他用户"];
}
- (void)viewDidLoad {
    [super viewDidLoad];
//    self.navigationController.navigationBar.translucent = NO;
//    self.navigationController.navigationBar.backgroundColor = [UIColor whiteColor];
    self.view.backgroundColor = [UIColor whiteColor];
    // Do any additional setup after loading the view.
    UIButton *back = [UIButton buttonWithType:UIButtonTypeCustom];
    [back setFrame:CGRectMake(0, 0, 30, 30)];
    [back setImage:[UIImage imageNamed:@"backButton"] forState:UIControlStateNormal];
    [back addTarget:self action:@selector(backTo) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *backItem = [[UIBarButtonItem alloc] initWithCustomView:back];
    self.navigationItem.leftBarButtonItem = backItem;
    self.ownScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64)];
    _ownScrollView.delegate = self;
    _ownScrollView.contentSize = CGSizeMake(0, 0);
    [self.view addSubview:_ownScrollView];
    [self createOwnInforView];
    
    [self createWorksTableview];
}
- (void)createOwnInforView
{
    self.HeaderInfor = [[ownInforView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height *0.2382) ownuid:_selfUid viewController:self];
    _HeaderInfor.backgroundColor = [UIColor clearColor];
    [_ownScrollView addSubview:_HeaderInfor];
    _HeaderInfor.userInteractionEnabled = YES;
    _HeaderInfor.avatar.userInteractionEnabled = YES;
    UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(BigAvatr)];
    [_HeaderInfor.avatar addGestureRecognizer:tapGesture];
    [_HeaderInfor.followedBtn addTarget:self action:@selector(goToFollowVC) forControlEvents:UIControlEventTouchUpInside];
    [_HeaderInfor.fansBtn addTarget:self action:@selector(goToFansVC) forControlEvents:UIControlEventTouchUpInside];
//    [_HeaderInfor.chatButton addTarget:self action:@selector(pushChatVC) forControlEvents:UIControlEventTouchUpInside];
    
}
- (void)createWorksTableview
{
    page = 1;
    self.worksTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, _HeaderInfor.frame.size.height, self.view.frame.size.width, self.view.frame.size.height - _HeaderInfor.frame.size.height - 64 - 45) style:UITableViewStylePlain];
    _worksTableView.showsVerticalScrollIndicator = NO;
    _worksTableView.delegate = self;
    _worksTableView.dataSource = self;
    _worksTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    [_ownScrollView addSubview:_worksTableView];
    [_ownScrollView bringSubviewToFront:_HeaderInfor];
    refreshHeader = [MJRefreshSystemHeaderView header];
    refreshHeader.scrollView = _worksTableView;
    refreshHeader.delegate = self;
    refreshFooter = [MJRefreshFooterView footer];
    refreshFooter.scrollView = _worksTableView;
    refreshFooter.delegate = self;
    
    _timeLine = [[UIImageView alloc]initWithFrame:CGRectMake(16, -_HeaderInfor.frame.size.height, 1.5, self.view.frame.size.height)];
    _timeLine.backgroundColor = [UIColor blackColor];
    [_worksTableView.viewForBaselineLayout addSubview:_timeLine];
    //    [_worksTableView.viewForBaselineLayout  addSubview:
    _timeLine.alpha = 1;
    
    UIButton *chatBtn = [[UIButton alloc] initWithFrame:CGRectMake(0, self.view.height - 64 - 45, self.view.width, 45)];
    chatBtn.backgroundColor = [UIColor blackColor];
    [chatBtn setImage:[UIImage imageNamed:@"message_white"] forState:UIControlStateNormal];
    [chatBtn setTitle:@"发私信" forState: UIControlStateNormal];
    chatBtn.titleLabel.font = [UIFont boldSystemFontOfSize:15];
    [chatBtn addTarget:self action:@selector(pushChatVC)forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:chatBtn];
    
}
#pragma mark -
#pragma mark tableview 协议
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return _worksArray.count;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return (0.24 * self.view.frame.size.height);
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *worksTableIdentifer = @"works";
    WorksTableViewCell *workstabelCell = [tableView dequeueReusableCellWithIdentifier:worksTableIdentifer];
    if (workstabelCell == nil) {
        workstabelCell = [[WorksTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:worksTableIdentifer];
    }
    if (_worksArray.count > 0) {
        workInfor *model = _worksArray[indexPath.row];
        workstabelCell.listdataModel = model;
    }
    
    return workstabelCell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    NSString *isPlay = [userDefaults objectForKey:@"isWiFiPlay"];
    NSString *pppp=[NSString stringWithFormat:@"%u",[self getNetworkTypeFromStatusBar]];
    if ([[self.navigationController.viewControllers firstObject] isKindOfClass:[playerTableViewController class]]) {
//        直接 pop 回第一个 vc
        self.player = (playerTableViewController *)[self.navigationController.viewControllers firstObject];
        if (([isPlay isEqualToString:@"1"]&&[pppp isEqualToString:@"5"])||[pppp isEqualToString:@"5"]||([isPlay isEqualToString:@"0"]&&![pppp isEqualToString:@"0"])||isPlay==nil){
            Player_ShowModel *playModel = [Player_ShowModel sharedInstance];
            workInfor *model = _worksArray[indexPath.row];
            NSString *showURL = [NSString stringWithFormat:@"http://123.57.1.143/api/work/%@/show", model.id];
             AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
            manager.responseSerializer = [AFJSONResponseSerializer serializer];
            NSString *header = [NSString stringWithFormat:@"Token %@:%@",[[NSUserDefaults standardUserDefaults] valueForKey:@"uid"], [[NSUserDefaults standardUserDefaults] valueForKey:@"token"]];
            [manager.requestSerializer setValue:header forHTTPHeaderField:@"authorization"];
            [manager GET:showURL parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                NSDictionary *dic = (NSDictionary *)responseObject;
                NSDictionary *dataDic = [dic valueForKey:@"data"];
                NSDictionary *linksDic = [dic valueForKey:@"links"];
                if ([[dic allKeys] containsObject:@"meta"]) {
                    NSDictionary *meta = [dic valueForKey:@"meta"];
                    NSString *userAvatar = [meta valueForKey:@"userAvatar"];
                    _player.locUserAvatar = userAvatar;
//                    NSArray *array = [meta valueForKey:@"playlist"];
//                    _player.playList = [NSMutableArray arrayWithArray:array];
                }
                [playModel setValuesForKeysWithDictionary:dataDic];
                if (![_player.workID isEqualToString:playModel.id]) {
                    _player.waveform = [linksDic valueForKey:@"waveform"];
                    _player.workID = model.id;
                    _player.isSelf = YES;
                    //保存是否love
                    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
                    NSString *islove = @"0";
                    if ([[dataDic objectForKey:@"liked"]boolValue]==YES) {
                        islove = @"1";
                    }else{
                        islove = @"0";
                    }
                    [userDefaults setObject:islove forKey:@"isLove"];
                    [userDefaults synchronize];
                    
                    [_player reloadViews:playModel];
                }
                [self.navigationController popToRootViewControllerAnimated:YES];
                
            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                
            }];
        }else{
            [JCAlertView showOneButtonWithTitle:@"你已开启仅Wifi环境播放" Message:@"可以去设置关闭此功能" ButtonType:JCAlertViewButtonTypeDefault ButtonTitle:@"确定" Click:^{
                
            }];
        }
    } else {
//         打开抽屉 刷新播放器
        UINavigationController *nv = (UINavigationController *)self.mm_drawerController.rightDrawerViewController;
        NSArray *array = nv.viewControllers;
        self.player = (playerTableViewController *)[array firstObject];
        WorksTableViewCell *cell = (WorksTableViewCell *)[tableView cellForRowAtIndexPath:indexPath];
        cell.listdataModel.play_count = [NSString stringWithFormat:@"%d",cell.listdataModel.play_count.intValue + 1];
        if (([isPlay isEqualToString:@"1"]&&[pppp isEqualToString:@"5"])||[pppp isEqualToString:@"5"]||([isPlay isEqualToString:@"0"]&&![pppp isEqualToString:@"0"])||isPlay==nil){
            Player_ShowModel *playModel = [Player_ShowModel sharedInstance];
            workInfor *model = _worksArray[indexPath.row];
            NSString *showURL = [NSString stringWithFormat:@"http://123.57.1.143/api/work/%@/show", model.id];
             AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
            manager.responseSerializer = [AFJSONResponseSerializer serializer];
            NSString *header = [NSString stringWithFormat:@"Token %@:%@",[[NSUserDefaults standardUserDefaults] valueForKey:@"uid"], [[NSUserDefaults standardUserDefaults] valueForKey:@"token"]];
            [manager.requestSerializer setValue:header forHTTPHeaderField:@"authorization"];
            [manager GET:showURL parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
                NSDictionary *dic = (NSDictionary *)responseObject;
                NSDictionary *dataDic = [dic valueForKey:@"data"];
                NSDictionary *linksDic = [dic valueForKey:@"links"];
                if ([[dic allKeys] containsObject:@"meta"]) {
                    NSDictionary *meta = [dic valueForKey:@"meta"];
                    NSString *userAvatar = [meta valueForKey:@"userAvatar"];
                    _player.locUserAvatar = userAvatar;
//                    NSArray *array = [meta valueForKey:@"playlist"];
//                    _player.playList = [NSMutableArray arrayWithArray:array]
//                    ;
                    playModel.comment_count = [meta valueForKey:@"count"];
                    ;
                }
                [playModel setValuesForKeysWithDictionary:dataDic];
                _player.waveform = [linksDic valueForKey:@"waveform"];
                _player.workID = model.id;
                _player.isSelf = YES;
                //保存是否love
                NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
                NSString *islove = @"0";
                if ([[dataDic objectForKey:@"liked"]boolValue]==YES) {
                    islove = @"1";
                }else{
                    islove = @"0";
                }
                [userDefaults setObject:islove forKey:@"isLove"];
                [userDefaults synchronize];
                [_player reloadViews:playModel];
                
                [self.mm_drawerController toggleDrawerSide:MMDrawerSideRight animated:YES completion:^(BOOL finished) {
                }];
                
            } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
                
            }];
        }else{
            [JCAlertView showOneButtonWithTitle:@"你已开启仅Wifi环境播放" Message:@"可以去设置关闭此功能" ButtonType:JCAlertViewButtonTypeDefault ButtonTitle:@"确定" Click:^{
                
            }];
        }

    }
}
-(NETWORK_state)getNetworkTypeFromStatusBar {
    UIApplication *app = [UIApplication sharedApplication];
    NSArray *subviews = [[[app valueForKey:@"statusBar"] valueForKey:@"foregroundView"] subviews];
    NSNumber *dataNetworkItemView = nil;
    for (id subview in subviews) {
        if([subview isKindOfClass:[NSClassFromString(@"UIStatusBarDataNetworkItemView") class]])     {
            dataNetworkItemView = subview;
            break;
        }
    }
    NETWORK_state nettype = NETWORK_state_NONE;
    NSNumber * num = [dataNetworkItemView valueForKey:@"dataNetworkType"];
    nettype = [num intValue];
    return nettype;
}
#pragma mark -
#pragma makr 网络请求
- (void)refreshViewBeginRefreshing:(MJRefreshBaseView *)refreshView
{
    BOOL isHeader = [refreshView isKindOfClass:[MJRefreshSystemHeaderView class]];
     // 第一页
    if (isHeader) {
        page = 1;
        refreshFooter.hidden = NO;
        [_worksArray removeAllObjects];
        [self AFNetworking:page uid:_selfUid refreshing:refreshView];
    }else { // 上拉加载更多
        if (pages == 1 || page >= pages) {
            refreshFooter.hidden = YES;
        } else {
            page++;
            [self AFNetworking:page uid:_selfUid refreshing:refreshView];
        }
    }
}
- (void)AFNetworking:(int)pag uid:(NSString *)uid refreshing:(MJRefreshBaseView *)refreshView
{
    NSString *url = [NSString stringWithFormat:@"http://123.57.1.143/api/user/%@/feeds?p=%d", uid, pag];
    NSString *requestheader = [NSString stringWithFormat:@"Token %@:%@",[[NSUserDefaults standardUserDefaults] valueForKey:@"uid"], [[NSUserDefaults standardUserDefaults] valueForKey:@"token"]];
    
     AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    [manager.requestSerializer setValue:requestheader forHTTPHeaderField:@"authorization"];
    [manager GET:url parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        NSDictionary *data = [responseObject valueForKey:@"data"];
        for (NSDictionary *dic in data) {
            workInfor *model = [[workInfor alloc] init];
            [model setValuesForKeysWithDictionary:dic];
            if (model.is_private == 0) {
                [_worksArray addObject:model];
            }
        }
        NSDictionary *meta = [responseObject valueForKey:@"meta"];
        if (meta != nil) {
            pages = [[meta valueForKey:@"pages"] intValue];
            if (pages == 1 || pag == pages) {
                refreshFooter.hidden = YES;
            }
        }
        if (_worksArray.count > 0) {
            _worksTableView.hidden = NO;
            [_worksTableView reloadData];
        } else {
            _worksTableView.hidden = YES;
            
            self.NoworksView = [[UIImageView alloc] initWithFrame:CGRectMake(0, _HeaderInfor.frame.size.height, _worksTableView.frame.size.width, _worksTableView.frame.size.width)];
            _NoworksView.image = [UIImage imageNamed:@"other_noWorks"];
            [self.view addSubview:_NoworksView];
        }
        [refreshView endRefreshing];
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    int header_height = (int)ceilf(_HeaderInfor.frame.size.height);
    int ownOffset = (int)_ownScrollView.contentOffset.y;
    if (![refreshHeader isRefreshing]) {
        if (_worksTableView.contentOffset.y > 10 && ownOffset !=(int)header_height) {
            if ([UIScreen mainScreen].bounds.size.width == 414.00) {
                _worksTableView.frame = CGRectMake(0, 175, self.view.frame.size.width, self.view.frame.size.height - 45);
            } else {
                _worksTableView.frame = CGRectMake(0, _HeaderInfor.frame.size.height, self.view.frame.size.width, self.view.frame.size.height - 45);
            }
            [UIView animateWithDuration:0.2 animations:^{
                _ownScrollView.contentOffset = CGPointMake(0, _HeaderInfor.frame.size.height);
            }];
            
        }
        
        if (scrollView.contentOffset.y < -10 && _ownScrollView.contentOffset.y != 0) {
            _worksTableView.frame = CGRectMake(0, _HeaderInfor.frame.size.height, self.view.frame.size.width, self.view.frame.size.height - _HeaderInfor.frame.size.height - 45);
            [UIView animateWithDuration:0.2 animations:^{
                _ownScrollView.contentOffset = CGPointMake(0, 0);
            }];
        }
    }
}
#pragma mark -
#pragma mark 跳转页面
- (void)backTo
{
    _ownScrollView.scrollEnabled = NO;
        [self.navigationController popViewControllerAnimated:YES];
}
- (void)goToFollowVC
{
    Follow_ViewController *follow = [[Follow_ViewController alloc] initWithSelfUid:_selfUid];
    [self.navigationController pushViewController:follow animated:YES];
}
- (void)goToFansVC
{
    Fans_ViewController *fans = [[Fans_ViewController alloc] initWithSelfUid:_selfUid];
    [self.navigationController pushViewController:fans animated:YES];
}
- (void)pushChatVC
{
    if ([[NSUserDefaults standardUserDefaults] valueForKey:@"uid"] == nil) {
        //提示请先登陆
        [JCAlertView showTwoButtonsWithTitle:@"未登录" Message:@"登录后才能继续操作" ButtonType:JCAlertViewButtonTypeCancel ButtonTitle:@"再看看" Click:^{
            
        } ButtonType:JCAlertViewButtonTypeDefault ButtonTitle:@"去登录" Click:^{
            [[AppDelegate shareDelegate] chooseRootViewController];
        }];
    } else {
        NSString *url = [NSString stringWithFormat:@"http://123.57.1.143/api/user/%@/talk", _selfUid];
         AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
        NSString *header = [NSString stringWithFormat:@"Token %@:%@",[[NSUserDefaults standardUserDefaults] valueForKey:@"uid"], [[NSUserDefaults standardUserDefaults] valueForKey:@"token"]];
        [manager.requestSerializer setValue:header forHTTPHeaderField:@"authorization"];
        [manager GET:url parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            if ([[responseObject valueForKey:@"status"] intValue]== 2) {
                chatViewController *chatController = [[chatViewController alloc] initWithConversationChatter:_selfUid conversationType:EMConversationTypeChat];
                chatController.chatName = self.titleLabel.text;
                [chatController checkMessageAvatar:self.HeaderInfor.avatarUrl];
                //    chat.chatAvatar = self.avatarURLStr;
                
                [self.navigationController pushViewController:chatController animated:YES];
            } else if ([[responseObject valueForKey:@"status"] intValue]== 0) {
                [JCAlertView showOneButtonWithTitle:@"提示" Message:@"你的积分不足" ButtonType:JCAlertViewButtonTypeDefault ButtonTitle:@"确定" Click:^{
                    
                }];
            } else {
                [JCAlertView showTwoButtonsWithTitle:@"提示" Message:[NSString stringWithFormat:@"花费3积分给 %@ 发送私信",self.titleLabel.text] ButtonType:JCAlertViewButtonTypeCancel ButtonTitle:@"取消" Click:^{
                    
                } ButtonType:JCAlertViewButtonTypeDefault ButtonTitle:@"确定" Click:^{
                    [self canPushChatController];
                }];
            }
            
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            
        }];
    }
}
- (void)canPushChatController
{
    NSString *url = [NSString stringWithFormat:@"http://123.57.1.143/api/user/%@/talk?confirm=1", _selfUid];
     AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    //    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript", @"text/html", @"text/plain", nil];
    NSString *header = [NSString stringWithFormat:@"Token %@:%@",[[NSUserDefaults standardUserDefaults] valueForKey:@"uid"], [[NSUserDefaults standardUserDefaults] valueForKey:@"token"]];
    [manager.requestSerializer setValue:header forHTTPHeaderField:@"authorization"];
    [manager GET:url parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        if ([[responseObject valueForKey:@"status"] intValue] == 1) {
            chatViewController *chatController = [[chatViewController alloc] initWithConversationChatter:_selfUid conversationType:EMConversationTypeChat];
            //    chatController.chatId = _selfUid;
            chatController.chatName = self.titleLabel.text;
            //    chat.chatAvatar = self.avatarURLStr;
            [self.navigationController pushViewController:chatController animated:YES];
            
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        
    }];
}
#pragma mark -
#pragma mark 头像缩放
- (void)BigAvatr
{
    UIView *_blackview = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.width, self.view.height)];
    _blackview.backgroundColor = [UIColor whiteColor];
    _blackview.alpha = 0;
    _blackview.tag = 203;
    _blackview.userInteractionEnabled = YES;
    [self.view addSubview:_blackview];
    UIImageView *bigImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, _blackview.frame.size.height / 2 - (_blackview.frame.size.width / 2), _blackview.frame.size.width, _blackview.frame.size.width)];
    [_blackview addSubview:bigImage];
    [UIView animateWithDuration:0.25f animations:^{
        _blackview.alpha = 1;
        if ([_HeaderInfor.userInformation.avatar isKindOfClass:[NSNull class]] || _HeaderInfor.userInformation.avatar.length < 5) {
            [bigImage setImage:[UIImage imageNamed:@"default_head@3x"]];
        } else {
            NSArray *array = [_HeaderInfor.userInformation.avatar componentsSeparatedByString:@"!cover"];
//            NSLog(@"%@", array);
            [bigImage setImageWithURL:[NSURL URLWithString:[array firstObject]]];
        }
    }];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(smallAvatar)];
    [_blackview addGestureRecognizer:tap];
}
- (void)smallAvatar
{
    UIView *blackView = [self.view viewWithTag:203];
    [UIView animateWithDuration:0.5f animations:^{
        blackView.alpha = 0.0f;
    }completion:^(BOOL finished) {
        [blackView removeFromSuperview];
    }];
}
#pragma mark -
#pragma mark 修改 title
- (void)changeTitle:(NSNotification *)notification
{
    NSDictionary *dic = notification.object;
    self.titleLabel.text = [dic valueForKey:@"username"];
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
